package com.atguigu.juc.chap09;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Taeyang
 * @date 2025/4/4
 */
public class VolatileAtomicDemo {

    public static void main(String[] args) {

        DataTwo data = new DataTwo();

        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                System.out.println(data.incr());
            }).start();
        }
    }

}

class DataOne {

    private Integer number = 0;

    public synchronized Integer incr() {
        return ++number;
    }
}

class DataTwo {

    private AtomicInteger number = new AtomicInteger(0);

    public synchronized Integer incr() {
        return number.incrementAndGet();
    }
}
